<?php
/*
 *
 * @package MoltX
 * @author $Author$
 * @version $Id$
 * @link $URL$
 * @copyright Copyright (c) 2005-2010, Matthew Oltendorf
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 *
 */

/*
 * @ignore
 */
if ( ! defined ( 'blink' ) )
{
	// Access denied.
	header ( $_SERVER [ 'SERVER_PROTOCOL' ] . ' 403 Forbidden' );
	echo '403 - Forbidden';

	exit;
}

// Ensure we have the blink_stream class loaded.
include_once blink_system . '/socket/stream.php';

/*
 * Blink storage class
 * @package Blink
 *
 * Singleton
 */
final class blink_storage
{
	/*
	 * Constructor function
	 *
	 * This is private to enforce singleton mode.
	 *
	 * @return null
	 */
	private function __construct ( )
	{
		return null;
	}

	/*
	 * Connect function
	 *
	 * @return null
	 */
	public static function connect ( $role, $remote )
	{
		$sock = ! $remote ? 'unix://' . blink_storage . '/socket/' . $role . '.sock' : 'tcp://' . $role;

		try
		{
			$resource = stream_socket_client ( $sock );
		}
		catch ( Exception $exception )
		{
			return false;
		}

		return new blink_socket ( $resource );
	}
}
